//
//  ViewController.m
//  GPUImage_Example
//
//  Created by 匡显铭 on 2017/6/1.
//  Copyright © 2017年 chuizhicai. All rights reserved.
//

#import "ViewController.h"
#import <GPUImage/GPUImageFramework.h>

@interface ViewController ()
@property (strong,nonatomic) UIImage * inputImage;
@property (weak,nonatomic) UIImage * outputImage;
@property (assign,nonatomic) CGFloat sizeScale;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _inputImage = [UIImage imageNamed:@"1.jpg"];
    CGFloat sizeScale = _inputImage.size.height/_inputImage.size.width;
    UIImageView *originalImageV = [[UIImageView alloc]init];
    [self.view addSubview:originalImageV];
    originalImageV.frame = CGRectMake(100, 100, 150, 150 * sizeScale);
    originalImageV.image = _inputImage;
    //添加滤镜效果
    [self smoothToonFilterTest];
    //把加滤镜后的图片显示出来
    UIImageView *finalImageV = [[UIImageView alloc]init];
    [self.view addSubview:finalImageV];
    finalImageV.frame = CGRectMake(100, 300, 150, 150 * sizeScale);
    finalImageV.image = _outputImage;
    NSLog(@"机器猫的世界你不懂");
    NSLog(@"我内心毫无波动，甚至还想背出师表");
    NSLog(@"hello,傻逼");
}

//黑白滤镜
- (void)sketchFilterTest {
    //使用黑白素描滤镜
    GPUImageSketchFilter *disFilter = [[GPUImageSketchFilter alloc]init];
    //设置要渲染的区域
    [disFilter forceProcessingAtSize:_inputImage.size];
    [disFilter useNextFrameForImageCapture];
    //获取数据源
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc]initWithImage:_inputImage];
    //添加滤镜
    [stillImageSource addTarget:disFilter];
    //开始渲染
    [stillImageSource processImage];
    //获取渲染后的图片
    UIImage *outputImage = [disFilter imageFromCurrentFramebuffer];
    _outputImage = outputImage;
}

//怀旧效果
- (void)sepiaFilterTest {
    //设置怀旧
    GPUImageSepiaFilter *disFilter = [[GPUImageSepiaFilter alloc]init];
    //设置要渲染的区域
    [disFilter forceProcessingAtSize:_inputImage.size];
    [disFilter useNextFrameForImageCapture];
    //获取数据源
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc]initWithImage:_inputImage];
    //添加滤镜
    [stillImageSource addTarget:disFilter];
    //开始渲染
    [stillImageSource processImage];
    //获取渲染后的图片
    UIImage *outputImage = [disFilter imageFromCurrentFramebuffer];
    _outputImage = outputImage;
    
}

//卡通
- (void)smoothToonFilterTest {
    //设置卡通
    GPUImageSmoothToonFilter *disFilter = [[GPUImageSmoothToonFilter alloc]init];
    //设置要渲染的区域
    [disFilter forceProcessingAtSize:_inputImage.size];
    [disFilter useNextFrameForImageCapture];
    //获取数据源
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc]initWithImage:_inputImage];
    //添加滤镜
    [stillImageSource addTarget:disFilter];
    //开始渲染
    [stillImageSource processImage];
    //获取渲染后的图片
    UIImage *outputImage = [disFilter imageFromCurrentFramebuffer];
    _outputImage = outputImage;
}

//朦胧加暗
- (void)hazeFilterTest {
    //设置朦胧加暗
    GPUImageHazeFilter *disFilter = [[GPUImageHazeFilter alloc]init];
    //设置要渲染的区域
    [disFilter forceProcessingAtSize:_inputImage.size];
    [disFilter useNextFrameForImageCapture];
    //获取数据源
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc]initWithImage:_inputImage];
    //添加滤镜
    [stillImageSource addTarget:disFilter];
    //开始渲染
    [stillImageSource processImage];
    //获取渲染后的图片
    UIImage *outputImage = [disFilter imageFromCurrentFramebuffer];
    _outputImage = outputImage;
}

//饱和
- (void)brightnessFilterTest {
    //设置饱和
    GPUImageBrightnessFilter *disFilter = [[GPUImageBrightnessFilter alloc]init];
    //设置要渲染的区域
    [disFilter forceProcessingAtSize:_inputImage.size];
    [disFilter useNextFrameForImageCapture];
    //获取数据源
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc]initWithImage:_inputImage];
    //添加滤镜
    [stillImageSource addTarget:disFilter];
    //开始渲染
    [stillImageSource processImage];
    //获取渲染后的图片
    UIImage *outputImage = [disFilter imageFromCurrentFramebuffer];
    _outputImage = outputImage;
}

//曝光度
- (void)exposureFilterTest {
    //设置饱和
    GPUImageExposureFilter *disFilter = [[GPUImageExposureFilter alloc]init];
    disFilter.exposure = 0.15;
    //设置要渲染的区域
    [disFilter forceProcessingAtSize:_inputImage.size];
    [disFilter useNextFrameForImageCapture];
    //获取数据源
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc]initWithImage:_inputImage];
    //添加滤镜
    [stillImageSource addTarget:disFilter];
    //开始渲染
    [stillImageSource processImage];
    //获取渲染后的图片
    UIImage *outputImage = [disFilter imageFromCurrentFramebuffer];
    _outputImage = outputImage;
}

@end
